from django.db import models

from utils.basemodel import BaseModel


# Create your models here.

class CategoryModel(BaseModel):
    c_name = models.CharField(max_length=50, verbose_name='分类名称')
    parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='父级分类',
                               related_name='children')
    is_hot = models.BooleanField(default=False, verbose_name='是否热门')
    is_good = models.BooleanField(default=False, verbose_name='是否精品')
    is_home = models.BooleanField(default=False, verbose_name='是否展示在首页')

    class Meta:
        db_table = 'fgcategroy'

    def __str__(self):
        return self.c_name


class TeacherModel(BaseModel):
    t_name = models.CharField(max_length=50, verbose_name='教师名称')
    job = models.CharField(max_length=50, verbose_name='职位')
    intro = models.TextField(verbose_name='简介')
    head_img = models.ImageField(upload_to='uploads', verbose_name='头像', null=True, blank=True)

    class Meta:
        db_table = 'fgteacher'

    def __str__(self):
        return self.t_name


class CourseModel(BaseModel):
    c_name = models.CharField(max_length=50, verbose_name='课程名称')
    category = models.ForeignKey(CategoryModel, on_delete=models.CASCADE, verbose_name='分类')
    teacher = models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name='教师')
    cover = models.ImageField(upload_to='uploads', verbose_name='封面', null=True, blank=True)
    level = models.IntegerField(
        choices=(('1', '初级'), ('2', '中级'), ('3', '高级')),
        verbose_name='难度等级', default=1
    )
    video = models.CharField(max_length=200, verbose_name='视频')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='价格')
    discount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='折扣价')
    is_hot = models.BooleanField(default=False, verbose_name='是否热门')
    is_home = models.BooleanField(default=False, verbose_name='是否展示在首页')
    read = models.IntegerField(default=0, verbose_name='阅读量')
    content = models.TextField(default='暂无', verbose_name='课程内容')

    class Meta:
        db_table = 'fgcourse'

    def __str__(self):
        return self.c_name
